import 'package:gameplay_flutter/m_room/model/room_base_model.dart';
import 'package:get/get.dart';

import '../lib_network/http_helper.dart';
import 'model/room_data_model.dart';
import 'room_api.dart';

class RoomMainController extends GetxController {

  var roomDatas = <RoomDataModel>[].obs;
  var currentIndex = 0.obs;
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  void addNewRoom(RoomDataModel roomData) async {
    roomDatas.clear();  // 清空所有元素
    roomDatas.add(roomData);  // 添加新元素
  }
  // void addNewRoom(RoomBaseInfo roomBaseInfo) async {
  //   roomBaseInfos.clear();  // 清空所有元素
  //   roomBaseInfos.add(roomBaseInfo);  // 添加新元素
  // }

  void enterExt(
      String roomNo,
      {String password = "",}) async {
    String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
    var res = await HttpHelper.instance().post(
      RoomApi.enterExt,
      body: {
        "roomNo": roomNo,
        "password": password,
        "timestamp": timestamp,
        "followUserId": "",
        "pushOrderMsgId": "",
      },
      showLoading: true,
      showToast: true,
    );
    if (res.result is Map<String, dynamic>) {
    }
  }

  void enterBase(
    String roomNo,
  {String password = "",}
  ) async {
    String timestamp = DateTime.now().millisecondsSinceEpoch.toString();
    var res = await HttpHelper.instance().post(
      RoomApi.enterBase,
      body: {
        "roomNo": roomNo,
        "timestamp": timestamp,
        "password": password,
        "isFromEditRoom": true,
      },
      showLoading: true,
      showToast: true,
    );
    if (res.result is Map<String , dynamic>) {
      RoomBaseModel roomBaseModel = RoomBaseModel.fromJson(res.result);

    }
  }
  void nextRoom() async {
    var res = await HttpHelper.instance().post(
      RoomApi.nextRoom,
      body: {
        "pageNum": 1,
        "pageSize": 1,
        "roomNo": 1,
        "intoPreview": true,
        "pageSignature": 1,
        "roomCategoryId": true,
      },
      showLoading: true,
      showToast: true,
    );
    if (res.result is Map<String , dynamic>) {
      RoomBaseModel roomBaseModel = RoomBaseModel.fromJson(res.result);

    }
  }

  void extraInfo() async {
    var res = await HttpHelper.instance().post(
      RoomApi.nextRoom,
      body: {
        "pageNum": 1,
        "pageSize": 1,
        "roomNo": 1,
        "intoPreview": true,
        "pageSignature": 1,
        "roomCategoryId": true,
      },
      showLoading: true,
      showToast: true,
    );
    if (res.result is Map<String , dynamic>) {
      RoomBaseModel roomBaseModel = RoomBaseModel.fromJson(res.result);

    }
  }
}
